package com.shop.shoporder.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.shoporder.common.HttpPost;
import com.shop.shoporder.common.MessageConstants;
import com.shop.shoporder.common.InterfaceVer;
import com.shop.shoporder.common.Response;
import com.shop.shoporder.entity.AdminLog;
import com.shop.shoporder.entity.HttpRequestConfig;
import com.shop.shoporder.entity.order.Cart;
import com.shop.shoporder.entity.order.Order;
import com.shop.shoporder.entity.order.ViewAdminOrderDetails;
import com.shop.shoporder.service.*;
import com.sun.tools.javac.util.Convert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/Order")
public class OrderController {
    @Autowired
    AdminLogService adminLogService;
    @Autowired
    OrderService orderService;
    @Autowired
    OrderAddressService orderAddressService;
    @Autowired
    LogisticsService logisticsService;
    @Autowired
    OrderReturnsService orderReturnsService;
    @Autowired
    ViewAdminOrderDetailsService viewAdminOrderDetailsService;
    @Autowired
    CartService cartService;
    @ResponseBody
    @RequestMapping(value = "/List", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response List(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                int page =0;
                int limit =10;
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("usernoId",(String) param.get("usernoId"));
                mapPa.put("orderStatus",(String) param.get("orderStatus"));
                mapPa.put("orderNo",(String) param.get("orderNo"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                int Intlimit=InterfaceVer.VerNumber((String) param.get("limit"));
                int Intpage=InterfaceVer.VerNumber((String) param.get("page"));
                page=Intpage;
                limit=Intlimit;
                PageHelper.startPage(page, limit);
                //读取数据表
                List<Order> orderList = orderService.adminSelectOrderList(mapPa,request);
                if (orderList != null&&orderList.size()>0) {
                    PageInfo<Order> pageInfo=new PageInfo<>(orderList);
                    int count=(int)pageInfo.getTotal();
                    return new Response(MessageConstants.MSG_SUCCESS, pageInfo.getList(), count, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/ShopList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response ShopList(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                int page =0;
                int limit =10;
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("usernoId",(String) param.get("usernoId"));
                mapPa.put("orderStatus",(String) param.get("orderStatus"));
                mapPa.put("orderNo",(String) param.get("orderNo"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                mapPa.put("zoneId",(String) param.get("zoneId"));
                int Intlimit=InterfaceVer.VerNumber((String) param.get("limit"));
                int Intpage=InterfaceVer.VerNumber((String) param.get("page"));
                page=Intpage;
                limit=Intlimit;
                PageHelper.startPage(page, limit);
                //读取数据表
                List<Order> orderList = orderService.adminSelectOrderShopList(mapPa,request);
                if (orderList != null&&orderList.size()>0) {
                    PageInfo<Order> pageInfo=new PageInfo<>(orderList);
                    int count=(int)pageInfo.getTotal();
                    return new Response(MessageConstants.MSG_SUCCESS, pageInfo.getList(), count, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/ShopUpdate", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response ShopUpdate(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:" + AID);
                System.out.println("接受参数：" + res);
                JSONObject param = JSONObject.parseObject(res);
                //读取数据表
                Order order = orderService.selectByOrderNo((String) param.get("orderNo"));
                if (order != null) {

                    String msgCode = "";
                    //提升等级
                    System.out.println("提升等级");
                    String uRes1 = HttpPost.GetMod(HttpRequestConfig.userServerUrl, "/User/Set", "id="+order.getUsernoId()+"&rankId=3");
                    JSONObject uResJSON1 = JSONObject.parseObject(uRes1);
                    msgCode = uResJSON1.get("code").toString();
                    if (!msgCode.equals("000000")) {//如果失败
                        return new Response(MessageConstants.MSG_SUCCESS, null, "提升等级失败", request);
                    }

                    //开店充值消费券66
                    System.out.println("开店充值消费券");
                    String xonsumptionRes1 = HttpPost.GetMod(HttpRequestConfig.finaceServerUrl, "/Finace/Add", "classify=4&type=66&state=1&userId=" + order.getUsernoId() + "&AID=" + AID + "&amount=" + order.getOrderMoney() + "&remark=开店保证金");
                    JSONObject xonsumptionResJSON1 = JSONObject.parseObject(xonsumptionRes1);
                    msgCode = xonsumptionResJSON1.get("code").toString();
                    if (!msgCode.equals("000000")) {//如果失败
                        return new Response(MessageConstants.MSG_SUCCESS, null, "充值失败", request);
                    }

                    //更新订单状态
                    Order order1 =new Order();
                    order1.setOrderId(order.getOrderId());
                    order1.setOrderStatus("705");
                    orderService.updateByPrimaryKeySelective(order1);

                    //添加管理日志
                    adminLogService.AddAdmin(1,order.getOrderId(),"保证金订单"+order.getOrderNo(),AID);



                    return new Response(MessageConstants.MSG_SUCCESS, order, 1, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/RefundList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response RefundList(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                int page =0;
                int limit =10;
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("usernoId",(String) param.get("usernoId"));
//                mapPa.put("orderStatus",(String) param.get("orderStatus"));
                mapPa.put("orderStatus","704");
                mapPa.put("orderNo",(String) param.get("orderNo"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                int Intlimit=InterfaceVer.VerNumber((String) param.get("limit"));
                int Intpage=InterfaceVer.VerNumber((String) param.get("page"));
                page=Intpage;
                limit=Intlimit;
                PageHelper.startPage(page, limit);
                //读取数据表
                List<Order> orderList = orderService.adminSelectOrderList1(mapPa,request);
                if (orderList != null&&orderList.size()>0) {
                    PageInfo<Order> pageInfo=new PageInfo<>(orderList);
                    int count=(int)pageInfo.getTotal();
                    return new Response(MessageConstants.MSG_SUCCESS, pageInfo.getList(), count, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/Refund", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response Refund(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                JSONObject param = JSONObject.parseObject(res);
                int orderId=InterfaceVer.VerNumber(param.get("orderId")==null?"0":param.get("orderId").toString());
                JSONObject jsonObject=null;
                //读取数据表
                 Order order = orderService.selectByPrimaryKey(orderId);
                 if(order!=null){
                     String orderStatus=order.getOrderStatus()==null?"-1":order.getOrderStatus();
                     if("707".equals(orderStatus)){
                         return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "订单已处理退款", request);
                     }
                     List<Cart> cartList =cartService.selectListByOrderNo(order.getOrderNo());
                     for (Cart cart:cartList) {
                         int isOrderFrom=cart.getRemark3()==null?-1:cart.getRemark3();
                         if(isOrderFrom==1){
                             return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "已导出发货单请联系管理员", request);
                         }
                     }
                     double cash=order.getCash()==null?0:order.getCash();
                     cash=0;
                     if(cash>0){
                         //微信退款
                         return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, "读取数据错误Wechat", request);
                     }else {
                         jsonObject=orderReturnsService.reFund(order);
                         //System.out.println("jsonObject:"+jsonObject.toJSONString());
                         if(jsonObject!=null){
                             String code = jsonObject.get("code").toString();
                             if("000000".equals(code)){
                                 order.setOrderStatus("707");
                                 order.setRefundAdminid(AID);
                                 order.setRefundTime(new Date());
                                 int resE=orderService.updateByPrimaryKeySelective(order);
                                 if(resE>0) {
                                     return new Response(MessageConstants.MSG_SUCCESS, jsonObject, "退款成功", request);
                                 }else {
                                     order.setOrderStatus("704");
                                     order.setRefundAdminid(0);
                                     order.setRefundTime(null);
                                     order.setRefundError("退款订单状态更新有误!");
                                     return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, "退款失败", request);
                                 }
                             }else {
                                 order.setRefundError(jsonObject.get("errorDetail").toString());
                                 int resE=orderService.updateByPrimaryKeySelective(order);
                                 return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, jsonObject.get("errorDetail").toString(), request);
                             }
                         }else {
                             return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, "退款失败", request);
                         }
                     }
                 }else {
                     return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, "读取数据错误2", request);
                 }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }


    @ResponseBody
    @RequestMapping(value = "/getDetails", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response getDetails(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        System.out.println("-------------");
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = (String)map.get("parm");
                //int AID  = Integer.parseInt(map.get("AID").toString());
                //System.out.println("AID:"+AID);
                //System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
//                int page =0;
//                int limit =10;
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("orderId",(String) param.get("orderId"));
//                mapPa.put("orderStatus",(String) param.get("orderStatus"));
//                mapPa.put("orderNo",(String) param.get("orderNo"));
//                mapPa.put("logName",(String) param.get("logName"));
//                mapPa.put("phone",(String) param.get("phone"));
                //PageHelper.startPage(page, limit);
                //读取数据表
                int orderId=0;try {
                    orderId=Integer.parseInt((String) param.get("orderId"));
                }catch (Exception e){}
                ViewAdminOrderDetails orderList = viewAdminOrderDetailsService.adminSelectOrderDetails(orderId);
                System.out.println(orderList.toString());
                if (orderList != null) {
//                    PageInfo<Order> pageInfo=new PageInfo<>(orderList);
//                    int count=(int)pageInfo.getTotal();
                    return new Response(MessageConstants.MSG_SUCCESS, orderList, 1, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/editAddressInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response editAddressInfo(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = (String)map.get("parm");
                //int AID  = Integer.parseInt(map.get("AID").toString());
                //System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("addressId",(String) param.get("addressId"));
                mapPa.put("cityId",(String) param.get("cityId"));
                mapPa.put("provinceId",(String) param.get("provinceId"));
                mapPa.put("areaId",(String) param.get("areaId"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                mapPa.put("detailAddr",(String) param.get("detailAddr"));
                mapPa.put("remark",(String) param.get("remark"));
                mapPa.put("orderNo",(String) param.get("orderNo"));

                mapPa.put("logType",(String) param.get("logType"));
                mapPa.put("logGoodsInfo",(String) param.get("logGoodsInfo"));

                Response response=orderAddressService.adminEditAddress(mapPa,request);
                return response;
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_SYS_ERROR, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/adminOrderCreate", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response adminOrderCreate(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        System.out.println("1111");
       // System.out.println(map1.get("sInfo")+"aaa");
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = (String)map.get("parm");
                System.out.println("res:"+res);
                int AID  = Integer.parseInt(map.get("AID").toString());
                JSONObject param = JSONObject.parseObject(res);
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("cityId",(String) param.get("cityId"));
                mapPa.put("provinceId",(String) param.get("provinceId"));
                mapPa.put("areaId",(String) param.get("areaId"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                mapPa.put("detailAddr",(String) param.get("detailAddr"));
                mapPa.put("orderRemark",(String) param.get("orderRemark"));
                mapPa.put("logType",(String) param.get("logType"));
                mapPa.put("AID",AID+"");
//                mapPa.put("logGoodsInfo",(String) param.get("logGoodsInfo"));
                mapPa.put("submitter",(String) param.get("submitter"));
                mapPa.put("sInfo",(String) param.get("sInfo"));
                Response response=orderService.adminAddOrder(mapPa,request);
                return response;
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_SYS_ERROR, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getLogInfoData", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response getLogInfoData(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = (String)map.get("parm");
                JSONObject param = JSONObject.parseObject(res);
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("logisticsNo",(String) param.get("logisticsNo"));
                Response response=logisticsService.getExpressNoData(mapPa,request);
                return response;
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_SYS_ERROR, null, 0, "读取数据错误1", request);
            }
        }
    }

    @RequestMapping(value = "/SuList", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response SuList(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                int page =0;
                int limit =10;
                Map<String,String> mapPa=new HashMap<>();
                mapPa.put("usernoId",(String) param.get("usernoId"));
                mapPa.put("orderStatus",(String) param.get("orderStatus"));
                mapPa.put("orderNo",(String) param.get("orderNo"));
                mapPa.put("logName",(String) param.get("logName"));
                mapPa.put("phone",(String) param.get("phone"));
                int Intlimit=InterfaceVer.VerNumber((String) param.get("limit"));
                int Intpage=InterfaceVer.VerNumber((String) param.get("page"));
                page=Intpage;
                limit=Intlimit;
                PageHelper.startPage(page, limit);
                //读取数据表
                List<Order> orderList = orderService.adminSelectOrderList(mapPa,request);
                System.out.println("YYYY");
                if (orderList != null&&orderList.size()>0) {
                    PageInfo<Order> pageInfo=new PageInfo<>(orderList);
                    int count=(int)pageInfo.getTotal();
                    System.out.println("BBB");
                    return new Response(MessageConstants.MSG_SUCCESS, pageInfo.getList(), count, "", request);
                } else {
                    return new Response(MessageConstants.MSG_SUCCESS, null, "没有数据", request);
                }
            } catch (Exception ex) {
                System.out.println("CCC");
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/upOrderStatus", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response upOrderStatus(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                System.out.println("AID:"+AID);
                System.out.println("接受参数："+res);
                JSONObject param = JSONObject.parseObject(res);
                int orderId=0;
                try {
                    orderId=Integer.parseInt(param.get("orderId").toString());
                }catch (Exception e){}
                Order order=new Order();
                order.setPayFinishTime(new Date());
                order.setFinishAdminid(AID);
                order.setOrderStatus("705");
                order.setOrderId(orderId);
                order.setFinishRemark((String) param.get("remark"));

                //int page =0;
                //int limit =10;
//                Map<String,String> mapPa=new HashMap<>();
//                mapPa.put("usernoId",(String) param.get("usernoId"));
//                mapPa.put("orderStatus",(String) param.get("orderStatus"));
//                mapPa.put("orderNo",(String) param.get("orderNo"));
//                mapPa.put("logName",(String) param.get("logName"));
//                mapPa.put("phone",(String) param.get("phone"));
                //int Intlimit=InterfaceVer.VerNumber((String) param.get("limit"));
                //int Intpage=InterfaceVer.VerNumber((String) param.get("page"));
                //page=Intpage;
                //limit=Intlimit;
                //PageHelper.startPage(page, limit);
                //读取数据表
                int resS = orderService.updateByPrimaryKeySelective(order);
                if(resS>0){
                    return new Response(MessageConstants.MSG_SUCCESS, 1, "成功", request);
                }else {
                    return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "失败", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }

    @ResponseBody
    @RequestMapping(value = "/RefundBH", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public Response RefundBH(HttpServletRequest request, @RequestBody JSONObject jsonParam) {
        Map<String, Object> map = InterfaceVer.Security(request, jsonParam);
        if (!map.get("code").toString().equals("000000")) {
            return new Response(MessageConstants.MSG_ACCESS_DENY, null, "接口参数错误", request);
        } else {
            try {
                String res = map.get("parm").toString();
                int AID  = Integer.parseInt(map.get("AID").toString());
                JSONObject param = JSONObject.parseObject(res);
                int orderId=InterfaceVer.VerNumber(param.get("orderId")==null?"0":param.get("orderId").toString());
                JSONObject jsonObject=null;
                //读取数据表
                Order order = orderService.selectByPrimaryKey(orderId);
                if(order!=null){
                    String orderStatus=order.getOrderStatus()==null?"-1":order.getOrderStatus();
                    if(!"704".equals(orderStatus)){
                        return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "订单状态有误!", request);
                    }
                    order.setOrderStatus("702");
                    order.setTurndownAdminid(AID);
                    order.setTurndownTime(new Date());
                    int resE=orderService.updateByPrimaryKeySelective(order);
                    if(resE>0){
                        return new Response(MessageConstants.MSG_SUCCESS, 1, "驳回成功", request);
                    }else {
                        return new Response(MessageConstants.MSG_ACCESS_DENY, 0, "驳回失败", request);
                    }
                }else {
                    return new Response(MessageConstants.MSG_ACCESS_DENY, jsonObject, "读取数据错误2", request);
                }
            } catch (Exception ex) {
                return new Response(MessageConstants.MSG_ACCESS_DENY, null, 0, "读取数据错误1", request);
            }
        }
    }


}
